<template>
  <div class="body">
    <!-- <el-row type="flex" justify="end" style="margin-bottom: 20px">
      <el-button type="primary" @click="openAdd()"> 新增 </el-button>
    </el-row> -->

    <el-row class="form">
      <el-row class="form-row" type="flex" justify="space-between">
        <div class="form-title">初步诊断</div>
        <div>
          <el-button type="primary" @click="addDiagnosis()"> 新增 </el-button>
        </div>
      </el-row>
      <el-row v-if="diagnosisForm.length == 0" class="no-data">
        <h3 align="center">无数据</h3>
      </el-row>
      <el-form v-for="(diagnosisItem, index) in diagnosisForm" :key="index" :model="diagnosisItem" label-width="80px">
        <el-row class="card">
          <el-row class="card-title" type="flex">
            <el-col :sm="22" class="right">
              <div class="content">
                {{ diagnosisItem.originData.createdAt }}
              </div>

              <div class="content">
                {{ diagnosisItem.originData.department }}
              </div>
              <div class="content">{{ diagnosisItem.originData.user }}</div>
            </el-col>
            <el-col :sm="2" class="right">
              <el-button type="primary" @click="saveOther(diagnosisItem)">
                保存
              </el-button>
            </el-col>
          </el-row>
          <!-- 初步诊断 -->
          <el-row class="card-content" style="margin-bottom: 20px">
            <span>诊断时间: </span>
            <el-date-picker v-if="index == diagnosisForm.length - 1" v-model="diagnosisItem.originData.diagnoseTime"
              type="datetime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" placeholder="选择时间" />
            <el-date-picker v-else v-model="diagnosisForm[diagnosisForm.length - 1].originData.diagnoseTime
              " type="datetime" value-format="yyyy-MM-dd HH:mm:ss" size="mini" placeholder="选择时间" readonly @focus="
                historyTips(
                  diagnosisForm[diagnosisForm.length - 1].originData.createdAt
                )
                " />
          </el-row>
          <el-row class="card-content">
            <div class="radio-flex">
              <span class="required-field">诊断类型: </span>
              <el-radio v-for="item in initialDiagnosisList1" :key="item.initialDiagnosisCode"
                v-model="diagnosisForm[index].initialDiagnosis" :label="item.initialDiagnosisCode">
                {{ item.initialDiagnosisName }}
              </el-radio>
              <el-radio v-model="diagnosisForm[index].initialDiagnosis" label="aorticdissection">
                主动脉夹层
              </el-radio>

              <el-radio v-if="diagnosisForm[index].initialDiagnosis == 'aorticdissection'
              " v-model="diagnosisForm[index].initialDiagnosisType" class="small-distance required-field"
                label="aorticdissection1">
                A型
              </el-radio>
              <el-radio v-if="diagnosisForm[index].initialDiagnosis == 'aorticdissection'
              " v-model="diagnosisForm[index].initialDiagnosisType" class="small-distance required-field"
                label="aorticdissection2">
                B型
              </el-radio>

              <el-radio v-for="item in initialDiagnosisList2" :key="item.initialDiagnosisCode"
                v-model="diagnosisForm[index].initialDiagnosis" :label="item.initialDiagnosisCode">
                {{ item.initialDiagnosisName }}
              </el-radio>
            </div>
          </el-row>
          <!-- 非ACS心源性胸痛  -->
          <el-row v-if="diagnosisForm[index].initialDiagnosis ==
            'Non-ACS_cardiogenic_chest_pain'
          " class="card-content">
            <div class="required-field">非ACS心源性胸痛</div>
            <div class="radio-flex radio-box">
              <el-checkbox-group v-model="diagnosisForm[index].chestPain">
                <el-checkbox v-for="item in chestPainList" :key="item.chestPainCode" :label="item.chestPainCode">
                  {{ item.chestPainName }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-row>
          <!-- 其他非心源性胸痛 -->
          <el-row v-if="diagnosisForm[index].initialDiagnosis == 'othercardiogenic'" class="card-content">
            <div class="required-field">其他非心源性胸痛</div>
            <div class="radio-flex">
              <el-checkbox-group v-model="diagnosisForm[index].cardiogenic" class="small">
                <el-checkbox v-for="item in cardiogenicList" :key="item.cardiogenicCode" :label="item.cardiogenicCode">
                  {{ item.cardiogenicName }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-row>
          <!-- 心功能评级 -->
          <el-row class="card-content"
            v-if="diagnosisForm[index].initialDiagnosis === 'siemidia' || diagnosisForm[index].initialDiagnosis === 'nstemidia' || diagnosisForm[index].initialDiagnosis === 'uadia'">
            <div class="radio-flex">
              <span :class="diagnosisForm[index].initialDiagnosis === 'uadia' ? '' : 'required-field'">心功能分级: </span>
              <el-radio v-for="item in initialHeartDiagnosisList" :key="item.initialHeartDiagnosisCode"
                v-model="diagnosisForm[index].initialHeartDiagnosis" :label="item.initialHeartDiagnosisCode">
                {{ item.initialHeartDiagnosisName }}
              </el-radio>
            </div>
          </el-row>
        </el-row>
      </el-form>
      <hr class="line-hr">
      <el-row class="form-row" type="flex" justify="space-between">
        <div class="required-field form-title">患者自愿放弃后续治疗

        </div>
        <el-radio-group v-model="outsData.isGiveUp">
          <el-radio label="1">是</el-radio>
          <el-radio label="0">否</el-radio>
        </el-radio-group>
      </el-row>

    </el-row>
    <el-row class="form">
      <el-row class="form-row" type="flex" justify="space-between">
        <div class="form-title">评分</div>
        <div>
          <el-button type="primary" @click="openAdd()"> 新增 </el-button>
        </div>
      </el-row>
      <el-row v-if="!hasData" class="no-data">
        <h3 align="center">无数据</h3>
      </el-row>
      <!-- 动态评分模板 -->
      <el-row v-for="(item, index) in scoreList" :key="item.index + index" class="card">
        <el-row class="card-title" type="flex">
          <el-col :sm="12" class="content"> {{ item.name }} </el-col>
          <el-col :sm="12" align="right">
            <el-button type="primary" @click="save(item)"> 保存 </el-button>
          </el-col>
        </el-row>
        <row v-if="!item.fieldType || item.fieldType != 'content'" :key="timer" :list="item.scoreClassList"
          :disabled="item.status == '0'" @dataEmit="getGradeSpan(item, index)" />
        <check v-if="!item.fieldType || item.fieldType != 'content'" v-model="item.data" :list="item.scoreClassList"
          style="padding-left: 30px" :disabled="item.status == '0'" @dataEmit="getGradeSpan(item, index)" />
        <el-row class="card-content card-content-result" type="flex">
          <div class="card-content-title">结果：</div>
          <div class="result-grade">
            <el-input v-model="item.grade" size="small" readonly />
          </div>
          <div class="result-score">
            <el-input v-model="item.mark" size="small" readonly />
          </div>
          <div class="card-content-title">分</div>
        </el-row>
        <!-- <el-row style="margin-bottom: 20px">
          <span v-if="item.mark" style="margin-right: 30px">
            得分：{{ item.mark }}
          </span>
          <span v-if="item.grade">等级：{{ item.grade }}</span>
        </el-row> -->
      </el-row>
      <!-- 老旧页面评分 -->
      <el-form v-for="(stemiFormItem, index) in stemiForm" :key="index" :model="stemiForm[index]" label-width="80px">
        <el-row class="card">
          <el-row class="card-title" type="flex">
            <el-col :sm="11" class="content">TIMI评分（STEMI）</el-col>
            <el-col :sm="11" class="right">
              <div class="content">
                {{ stemiFormItem.originData.createdAt }}
              </div>

              <div class="content">
                {{ stemiFormItem.originData.department }}
              </div>
              <div class="content">{{ stemiFormItem.originData.user }}</div>
            </el-col>
            <el-col :sm="2" class="right">
              <el-button type="primary" @click="saveOther(stemiFormItem)">
                保存
              </el-button>
            </el-col>
          </el-row>
          <el-row class="card-content" type="flex">
            <div class="card-content-subTitle">病史：</div>
            <div class="radio-flex">
              <el-checkbox-group v-model="stemiForm[index].stemiMedicalHistory" @change="stemiChange(index)">
                <el-col v-for="stemiMedicalHistoryItem in stemiMedicalHistoryList"
                  :key="stemiMedicalHistoryItem.stemiMedicalHistoryCode" :sm="8">
                  <el-checkbox :label="stemiMedicalHistoryItem.stemiMedicalHistoryCode">
                    {{ stemiMedicalHistoryItem.stemiMedicalHistoryName }}
                  </el-checkbox>
                </el-col>
              </el-checkbox-group>
            </div>
          </el-row>
          <el-row class="card-content" type="flex">
            <div class="card-content-subTitle">检查：</div>
            <div class="radio-flex check">
              <el-checkbox-group v-model="stemiForm[index].stemiInspect" @change="stemiChange(index)">
                <el-checkbox v-for="stemiInspectItem in stemiInspectList" :key="stemiInspectItem.stemiInspectCode"
                  :label="stemiInspectItem.stemiInspectCode">
                  {{ stemiInspectItem.stemiInspectName }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-row>

          <el-row class="card-content card-content-result" type="flex">
            <div class="card-content-title">结果：</div>
            <div class="result-grade">
              <el-input v-model="stemiForm[index].grade" size="small" readonly />
            </div>
            <div class="result-score">
              <el-input v-model="stemiForm[index].score" size="small" readonly />
            </div>
            <div class="card-content-title">分</div>
          </el-row>
        </el-row>
      </el-form>

      <el-form v-for="(nstemiUAFormItem, nstemiUAFormIndex) in nstemiUAForm" :key="'nstemiUA' + nstemiUAFormIndex"
        :model="nstemiUAForm[nstemiUAFormIndex]" label-width="80px">
        <el-row class="card">
          <el-row class="card-subTitle" type="flex">
            <el-col :sm="11" class="content">TIMI评分（NSTEMI/UA）</el-col>
            <el-col :sm="11" class="right">
              <div class="content">
                {{ nstemiUAFormItem.originData.createdAt }}
              </div>

              <div class="content">
                {{ nstemiUAFormItem.originData.department }}
              </div>
              <div class="content">{{ nstemiUAFormItem.originData.user }}</div>
            </el-col>
            <el-col :sm="2" class="right">
              <el-button type="primary" @click="saveOther(nstemiUAFormItem)">
                保存
              </el-button>
            </el-col>
          </el-row>
          <el-row class="card-content" type="flex">
            <div class="card-content-subTitle">项目：</div>
            <div class="radio-flex">
              <el-checkbox-group v-model="nstemiUAForm[nstemiUAFormIndex].nstemiProject"
                @change="nstemiChange(nstemiUAFormIndex)">
                <el-row>
                  <el-col :sm="6">
                    <el-checkbox label="nstemi1"> 年龄（≥65岁） </el-checkbox>
                  </el-col>
                  <el-col :sm="12">
                    <el-checkbox label="nstemi2">
                      ≥3个冠心危险因子（家族史、高血压、高胆固醇、糖尿病、吸烟等）
                    </el-checkbox>
                  </el-col>
                  <el-col :sm="6">
                    <el-checkbox label="nstemi3">
                      已知冠心病（狭窄≥50%）
                    </el-checkbox>
                  </el-col>
                </el-row>
                <el-row class="row">
                  <el-col :sm="6">
                    <el-checkbox label="nstemi4">
                      1周内使用阿司匹林
                    </el-checkbox>
                  </el-col>
                  <el-col :sm="12">
                    <el-checkbox label="nstemi5">
                      近期（≤24h）严重心绞痛（2次以上AP或静息AP）
                    </el-checkbox>
                  </el-col>
                  <el-col :sm="6">
                    <el-checkbox label="nstemi6">
                      心肌损伤指标升高
                    </el-checkbox>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :sm="8">
                    <el-checkbox label="nstemi7"> ST段偏移≥0.05mm </el-checkbox>
                  </el-col>
                </el-row>
              </el-checkbox-group>
            </div>
          </el-row>
          <el-row class="card-content card-content-result" type="flex">
            <div class="card-content-title">结果：</div>
            <div class="result-grade">
              <el-input v-model="nstemiUAForm[nstemiUAFormIndex].grade" readonly size="small" />
            </div>
            <div class="result-score">
              <el-input v-model="nstemiUAForm[nstemiUAFormIndex].score" size="small" readonly />
            </div>
            <div class="card-content-title">分</div>
          </el-row>
        </el-row>
      </el-form>
      <el-form v-for="(graceFormItem, graceFormIndex) in graceForm" :key="'grace' + graceFormIndex"
        :model="graceForm[graceFormIndex]" label-width="80px" style="margin-bottom: 20px">
        <el-row class="card">
          <el-row class="card-subTitle" type="flex">
            <el-col :sm="11" class="content">GRACE 分级</el-col>
            <el-col :sm="11" class="right">
              <div class="content">
                {{ graceFormItem.originData.createdAt }}
              </div>

              <div class="content">
                {{ graceFormItem.originData.department }}
              </div>
              <div class="content">{{ graceFormItem.originData.user }}</div>
            </el-col>
            <el-col :sm="2" class="right">
              <el-button type="primary" @click="saveOther(graceFormItem)">
                保存
              </el-button>
            </el-col>
          </el-row>
          <el-row class="card-content">Killip 分级</el-row>
          <el-row v-for="graceKillipClassificationItem in graceKillipClassificationList"
            :key="graceKillipClassificationItem.graceKillipClassificationCode" class="card-content">
            <el-radio v-model="graceForm[graceFormIndex].graceKillipClassification" :label="graceKillipClassificationItem.graceKillipClassificationCode
              " style="margin-top: 20px">
              {{ graceKillipClassificationItem.graceKillipClassificationName }}
            </el-radio>
          </el-row>
          <el-row class="card-content" style="margin-top: 20px">
            收缩压（mmHg）
          </el-row>

          <el-row class="card-content">
            <el-radio v-for="gracePressureClassificationItem in gracePressureClassificationList" :key="gracePressureClassificationItem.gracePressureClassificationCode
              " v-model="graceForm[graceFormIndex].gracePressureClassification" :label="gracePressureClassificationItem.gracePressureClassificationCode
                " style="margin-top: 20px">
              {{
                gracePressureClassificationItem.gracePressureClassificationName
              }}
            </el-radio>
          </el-row>
          <el-row class="card-content" style="margin-top: 20px"> 心率 </el-row>
          <el-row class="card-content">
            <el-radio v-for="graceHeartRateClassificationItem in graceHeartRateClassificationList" :key="graceHeartRateClassificationItem.graceHeartRateClassificationCode
              " v-model="graceForm[graceFormIndex].graceHeartRateClassification" :label="graceHeartRateClassificationItem.graceHeartRateClassificationCode
                " style="margin-top: 20px">
              {{
                graceHeartRateClassificationItem.graceHeartRateClassificationName
              }}
            </el-radio>
          </el-row>
          <el-row class="card-content" style="margin-top: 20px">
            年龄（岁）
          </el-row>
          <el-row class="card-content">
            <el-radio v-for="graceAgeClassificationItem in graceAgeClassificationList"
              :key="graceAgeClassificationItem.graceAgeClassificationCode"
              v-model="graceForm[graceFormIndex].graceAgeClassification"
              :label="graceAgeClassificationItem.graceAgeClassificationCode" style="margin-top: 20px">
              {{ graceAgeClassificationItem.graceAgeClassificationName }}
            </el-radio>
          </el-row>
          <el-row class="card-content" style="margin-top: 20px">
            CK(umol/L)
          </el-row>
          <el-row class="card-content">
            <el-radio v-for="graceCkClassificationItem in graceCkClassificationList"
              :key="graceCkClassificationItem.graceCkClassificationCode"
              v-model="graceForm[graceFormIndex].graceCkClassification"
              :label="graceCkClassificationItem.graceCkClassificationCode" style="margin-top: 20px">
              {{ graceCkClassificationItem.graceCkClassificationName }}
            </el-radio>
          </el-row>
          <el-row class="card-content" style="margin-top: 20px">
            危险因素
          </el-row>
          <el-row class="card-content">
            <el-radio v-for="graceDangerClassificationItem in graceDangerClassificationList"
              :key="graceDangerClassificationItem.graceDangerClassificationCode"
              v-model="graceForm[graceFormIndex].graceDangerClassification" :label="graceDangerClassificationItem.graceDangerClassificationCode
                " style="margin-top: 20px">
              {{ graceDangerClassificationItem.graceDangerClassificationName }}
            </el-radio>
          </el-row>
        </el-row>
      </el-form>
      <el-form v-for="(killipItem, killipFormIndex) in killipClassificationForm"
        :key="'killipClassification' + killipFormIndex" :model="killipClassificationForm[killipFormIndex]"
        label-width="80px">
        <el-row class="card">
          <el-row class="card-subTitle" type="flex">
            <el-col :sm="11" class="content">Killip 分级</el-col>
            <el-col :sm="11" class="right">
              <div class="content">{{ killipItem.originData.createdAt }}</div>

              <div class="content">{{ killipItem.originData.department }}</div>
              <div class="content">{{ killipItem.originData.user }}</div>
            </el-col>
            <el-col :sm="2" class="right">
              <el-button type="primary" @click="saveOther(killipItem)">
                保存
              </el-button>
            </el-col>
          </el-row>
          <el-row v-for="killipClassificationItem in killipClassificationList"
            :key="killipClassificationItem.killipClassificationCode" class="card-content">
            <el-radio v-model="killipClassificationForm[killipFormIndex].killipClassification
              " :label="killipClassificationItem.killipClassificationCode" style="margin-bottom: 20px">
              {{ killipClassificationItem.killipClassificationName }}
            </el-radio>
          </el-row>
        </el-row>
      </el-form>
      <el-form v-for="(nyhaItem, nyhaFormIndex) in nyhaClassificationForm" :key="'nyhaClassification' + nyhaFormIndex"
        :model="nyhaClassificationForm[nyhaFormIndex]" label-width="80px">
        <el-row class="card">
          <el-row class="card-subTitle" type="flex">
            <el-col :sm="11" class="content">NYHA 分级</el-col>
            <el-col :sm="11" class="right">
              <div class="content">{{ nyhaItem.originData.createdAt }}</div>

              <div class="content">{{ nyhaItem.originData.department }}</div>
              <div class="content">{{ nyhaItem.originData.user }}</div>
            </el-col>
            <el-col :sm="2" class="right">
              <el-button type="primary" @click="saveOther(nyhaItem)">
                保存
              </el-button>
            </el-col>
          </el-row>
          <el-row v-for="nyhaClassificationItem in nyhaClassificationList"
            :key="nyhaClassificationItem.nyhaClassificationCode" class="card-content">
            <el-radio v-model="nyhaClassificationForm[nyhaFormIndex].nyhaClassification"
              :label="nyhaClassificationItem.nyhaClassificationCode" style="margin-bottom: 20px">
              {{ nyhaClassificationItem.nyhaClassificationName }}
            </el-radio>
          </el-row>
        </el-row>
      </el-form>
    </el-row>

    <el-row class="form">
      <el-row class="form-row" type="flex" justify="space-between">
        <div class="form-title">并发症</div>
        <div>
          <el-button type="primary" @click="addComplication()">
            新增
          </el-button>
        </div>
      </el-row>
      <el-row v-if="complicationForm.length == 0" class="no-data">
        <h3 align="center">无数据</h3>
      </el-row>
      <el-row v-for="(complicationFormItem, index) in complicationForm" :key="'complication' + index" class="card">
        <el-row class="card-title" type="flex">
          <el-col :sm="22" class="right">
            <div class="content">
              {{ complicationFormItem.originData.createdAt }}
            </div>

            <div class="content">
              {{ complicationFormItem.originData.department }}
            </div>
            <div class="content">
              {{ complicationFormItem.originData.user }}
            </div>
          </el-col>
          <el-col :sm="2" class="right">
            <el-button type="primary" @click="saveOther(complicationFormItem)">
              保存
            </el-button>
          </el-col>
        </el-row>
        <el-row class="card-content">
          <el-checkbox-group v-model="complicationForm[index].complication" class="item">
            <el-col :sm="24" class="row">
              <span>循环系统并发症: </span>
            </el-col>
            <!-- <el-col :sm="3" class="row">
              <el-checkbox label="complication1">死亡</el-checkbox>
            </el-col> -->
            <el-col :sm="3" class="row">
              <el-checkbox label="complication2">心律失常</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication3">心源性休克</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication4">心力衰竭</el-checkbox>
            </el-col>
            <!-- <el-col :sm="3" class="row">
              <el-checkbox label="complication5">机械并发症</el-checkbox>
            </el-col> -->
            <el-col :sm="3" class="row">
              <el-checkbox label="complication6">血栓形成和栓塞</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication7">室壁瘤形成</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication8">心肌梗死后综合征</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication9">心包填塞</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication10">动脉瘤破裂</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication13">脑卒中</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication17">肺动脉高压</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication21">出血</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication23">合并出血</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication24">合并心衰</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication25">合并恶性心律失常</el-checkbox>
            </el-col>

            <el-col :sm="24" class="row">
              <span>呼吸系统并发症: </span>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication15">呼吸衰竭</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication16">咯血</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication18">纵隔气肿</el-checkbox>
            </el-col>

            <el-col :sm="24" class="row">
              <span>其他并发症: </span>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication11">急性肾功能衰竭</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication12">截瘫</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication14">低氧血症</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication19">皮下气肿</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication20">感染性炎症</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication22">消化道穿孔</el-checkbox>
            </el-col>


          </el-checkbox-group>
        </el-row>
      </el-row>
    </el-row>
    <el-dialog title="新增评分" :visible.sync="openAddDialog" custom-class="estimateAddDialog" width="1450px" center>
      <el-row style="margin: 0 45px 20px 45px" type="flex">
        <div style="align-items: center; display: flex; flex: 0 0 80px">
          评分类别：
        </div>
        <el-select v-model="select" @change="gradeInit">
          <el-option v-for="item in list.filter((el) => el.status !== '0')" :key="item.id" :label="item.name"
            :value="item.id" />
        </el-select>
      </el-row>
      <el-row v-for="item in list.filter((data) => data.id == select)" :key="item.index" :style="border" class="card">
        <el-row class="card-title" style="margin-bottom: 20px" type="flex">
          <el-col :sm="10" class="content"> {{ item.name }} </el-col>
          <el-col :sm="14">
            <span v-if="addMark || addMark === 0" style="margin-right: 30px">
              得分：{{ addMark }}
            </span>
            <span v-if="addGrade">等级：{{ addGrade }}</span>
          </el-col>
        </el-row>
        <row v-if="!item.fieldType || item.fieldType != 'content'" :list="item.scoreClassList"
          @dataEmit="getAddGrade(item)" />
        <check v-if="!item.fieldType || item.fieldType != 'content'" v-model="item.data" :list="item.scoreClassList"
          style="padding-left: 30px" @dataEmit="getAddGrade(item)" />
      </el-row>
      <div slot="footer">
        <el-button @click="openAddDialog = false">取 消</el-button>
        <el-button type="primary" @click="addConfirm"> 确 定 </el-button>
      </div>
    </el-dialog>
    <el-dialog title="新增初步诊断" :visible.sync="openAddDiagnosis" custom-class="estimateAddDialog" width="1000px" center>
      <el-form :model="addDiagnosisForm" label-width="80px">
        <el-row class="card" :style="border">
          <!-- 初步诊断 -->
          <el-row class="card-content" style="margin-bottom: 20px">
            <span>诊断时间: </span>
            <el-date-picker v-model="addDiagnosisForm.originData.diagnoseTime" type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss" size="mini" placeholder="选择时间" />
          </el-row>
          <el-row class="card-content">
            <div class="radio-flex">
              <span class="required-field">诊断类型: </span>
              <el-radio v-for="item in initialDiagnosisList1" :key="item.initialDiagnosisCode"
                v-model="addDiagnosisForm.initialDiagnosis" :label="item.initialDiagnosisCode">
                {{ item.initialDiagnosisName }}
              </el-radio>
              <el-radio v-model="addDiagnosisForm.initialDiagnosis" label="aorticdissection">
                主动脉夹层
              </el-radio>
              <el-radio v-if="addDiagnosisForm.initialDiagnosis == 'aorticdissection'"
                v-model="addDiagnosisForm.initialDiagnosisType" class="small-distance required-field"
                label="aorticdissection1">
                A型
              </el-radio>
              <el-radio v-if="addDiagnosisForm.initialDiagnosis == 'aorticdissection'"
                v-model="addDiagnosisForm.initialDiagnosisType" class="small-distance required-field"
                label="aorticdissection2">
                B型
              </el-radio>
              <el-radio v-for="item in initialDiagnosisList2" :key="item.initialDiagnosisCode"
                v-model="addDiagnosisForm.initialDiagnosis" :label="item.initialDiagnosisCode">
                {{ item.initialDiagnosisName }}
              </el-radio>
            </div>
          </el-row>
          <!-- 非ACS心源性胸痛  -->
          <el-row v-if="addDiagnosisForm.initialDiagnosis ==
            'Non-ACS_cardiogenic_chest_pain'
          " class="card-content">
            <div class="radio-flex radio-box">
              <div class="required-field">非ACS心源性胸痛类型</div>
              <el-checkbox-group v-model="addDiagnosisForm.chestPain">
                <el-checkbox v-for="item in chestPainList" :key="item.chestPainCode" :label="item.chestPainCode">
                  {{ item.chestPainName }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-row>
          <!-- 其他非心源性胸痛 -->
          <el-row v-if="addDiagnosisForm.initialDiagnosis == 'othercardiogenic'" class="card-content">
            <div class="radio-flex">
              <div class="required-field">其他非心源性胸痛类型</div>
              <el-checkbox-group v-model="addDiagnosisForm.cardiogenic" class="small">
                <el-checkbox v-for="item in cardiogenicList" :key="item.cardiogenicCode" :label="item.cardiogenicCode">
                  {{ item.cardiogenicName }}
                </el-checkbox>
              </el-checkbox-group>
            </div>
          </el-row>
          <!-- 心功能评级 -->
          <el-row class="card-content"
            v-if="addDiagnosisForm.initialDiagnosis === 'siemidia' || addDiagnosisForm.initialDiagnosis === 'nstemidia' || addDiagnosisForm.initialDiagnosis === 'uadia'">
            <div class="radio-flex">
              <span :class="addDiagnosisForm.initialDiagnosis === 'uadia' ? '' : 'required-field'">心功能分级: </span>
              <el-radio v-for="item in initialHeartDiagnosisList" :key="item.initialHeartDiagnosisCode"
                v-model="addDiagnosisForm.initialHeartDiagnosis" :label="item.initialHeartDiagnosisCode">
                {{ item.initialHeartDiagnosisName }}
              </el-radio>
            </div>
          </el-row>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button @click="openAddDiagnosis = false">取 消</el-button>
        <el-button type="primary" @click="addDiagnosisConfirm('addDiagnosisForm', '初步诊断')">
          确 定
        </el-button>
      </div>
    </el-dialog>
    <el-dialog title="并发症" :visible.sync="openAddComplication" custom-class="estimateAddDialog" width="1200px" center>
      <el-row class="card" :style="border">
        <el-row class="card-content">
          <el-checkbox-group v-model="addComplicationForm.complication" class="item">
            <el-col :sm="24" class="row">
              <span>循环系统并发症: </span>
            </el-col>
            <!-- <el-col :sm="3" class="row">
              <el-checkbox label="complication1">死亡</el-checkbox>
            </el-col> -->
            <el-col :sm="3" class="row">
              <el-checkbox label="complication2">心律失常</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication3">心源性休克</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication4">心力衰竭</el-checkbox>
            </el-col>
            <!-- <el-col :sm="3" class="row">
              <el-checkbox label="complication5">机械并发症</el-checkbox>
            </el-col> -->
            <el-col :sm="3" class="row">
              <el-checkbox label="complication6">血栓形成和栓塞</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication7">室壁瘤形成</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication8">心肌梗死后综合征</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication9">心包填塞</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication10">动脉瘤破裂</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication13">脑卒中</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication17">肺动脉高压</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication21">出血</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication23">合并出血</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication24">合并心衰</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication25">合并恶性心律失常</el-checkbox>
            </el-col>
            <el-col :sm="24" class="row">
              <span>呼吸系统并发症: </span>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication15">呼吸衰竭</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication16">咯血</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication18">纵隔气肿</el-checkbox>
            </el-col>
            <el-col :sm="24" class="row">
              <span>其他并发症: </span>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication11">急性肾功能衰竭</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication12">截瘫</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication14">低氧血症</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication19">皮下气肿</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication20">感染性炎症</el-checkbox>
            </el-col>
            <el-col :sm="3" class="row">
              <el-checkbox label="complication22">消化道穿孔</el-checkbox>
            </el-col>


          </el-checkbox-group>
        </el-row>
      </el-row>
      <div slot="footer">
        <el-button @click="openAddComplication = false">取 消</el-button>
        <el-button type="primary" @click="addDiagnosisConfirm('addComplicationForm', '并发症')">
          确 定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Check from '@/components/scoreRow/Check'
import Row from '@/components/scoreRow/Row'
import {
  selectScoreClassAll,
  selectScoreConclusion,
  saveScores,
  selectScores,
  updateScores,
  findDiagnosesData,
  saveDiagnoses
} from '@/api/green-channel/diagnoses'
import {
  getOutsData,
  saveOutsData
} from '@/api/green-channel/outcome'
export default {
  name: 'DiagnosticEstimate',
  components: {
    Row,
    Check
  },

  props: {
    checkrowdata: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      border: {
        border: '1px dashed #DCDFE6',
        'border-radius': '4px',
        'margin-bottom': '20px',
        'padding-top': '10px',
        'padding-left': '30px'
      },
      hasData: false,
      list: [],
      scoreList: [],
      scoresList: [],
      select: '',
      openAddDialog: false,
      addDiagnosisForm: {
        originData: {},
        chestPain: [],
        cardiogenic: []
      },
      openAddDiagnosis: false,
      addComplicationForm: {
        originData: {},
        complication: []
      },
      openAddComplication: false,
      addGrade: '',
      addMark: '',
      timer: '',
      diagnosisForm: [],
      complicationForm: [],
      // TIMI评分(stemi)
      stemiForm: [],
      // TIMI评分（NSTEMI/UA）
      nstemiUAForm: [],
      // grace 评分
      graceForm: [],
      // Killip 分级
      killipClassificationForm: [],
      // NYHA 分级
      nyhaClassificationForm: [],
      initialDiagnosisList1: [
        {
          initialDiagnosisName: '未明确诊断',
          initialDiagnosisCode: 'undetermined'
        },
        {
          initialDiagnosisName: 'STEMI',
          initialDiagnosisCode: 'siemidia'
        },
        {
          initialDiagnosisName: 'NSTEMI',
          initialDiagnosisCode: 'nstemidia'
        },
        {
          initialDiagnosisName: 'UA',
          initialDiagnosisCode: 'uadia'
        }
      ],
      initialDiagnosisList2: [
        {
          initialDiagnosisName: '肺动脉栓塞',
          initialDiagnosisCode: 'pulmonary'
        },
        {
          initialDiagnosisName: '非ACS心源性胸痛',
          initialDiagnosisCode: 'Non-ACS_cardiogenic_chest_pain'
        },
        {
          initialDiagnosisName: '其他非心源性胸痛',
          initialDiagnosisCode: 'othercardiogenic'
        },
        {
          initialDiagnosisName: '胸痛待查',
          initialDiagnosisCode: 'chest_pain_unknown'
        },
        {
          initialDiagnosisName: '胸闷待查',
          initialDiagnosisCode: 'chest_tightness_unknown'
        }
      ],
      initialDiagnosisList3: [
        {
          initialDiagnosisName: '主动脉夹层',
          initialDiagnosisCode: 'aorticdissection'
        }
      ],

      // 初步诊断LIST表
      chestPainList: [
        {
          chestPainName: '心律失常',
          chestPainCode: 'asc1'
        },
        {
          chestPainName: '扩张性心肌病',
          chestPainCode: 'asc2'
        },
        {
          chestPainName: '缺血性心肌病',
          chestPainCode: 'asc3'
        },
        {
          chestPainName: '肥厚型心肌病',
          chestPainCode: 'asc4'
        },
        {
          chestPainName: '心肌炎',
          chestPainCode: 'asc5'
        },
        {
          chestPainName: '冠心病',
          chestPainCode: 'asc6'
        },
        {
          chestPainName: '瓣膜性心脏病',
          chestPainCode: 'asc7'
        },
        {
          chestPainName: '陈旧性心肌梗死',
          chestPainCode: 'asc8'
        },
        {
          chestPainName: '心绞痛',
          chestPainCode: 'asc9'
        },
        {
          chestPainName: '心悸',
          chestPainCode: 'asc10'
        },
        {
          chestPainName: '房颤',
          chestPainCode: 'asc11'
        },
        {
          chestPainName: '高血压',
          chestPainCode: 'asc12'
        },
        {
          chestPainName: '心衰',
          chestPainCode: 'asc13'
        },
        {
          chestPainName: '房扑',
          chestPainCode: 'asc14'
        },
        {
          chestPainName: '室早',
          chestPainCode: 'asc15'
        },
        {
          chestPainName: '房早',
          chestPainCode: 'asc16'
        },
        {
          chestPainName: '室上速',
          chestPainCode: 'asc17'
        },
        {
          chestPainName: '心包炎',
          chestPainCode: 'asc18'
        },
        {
          chestPainName: '心肌桥',
          chestPainCode: 'asc19'
        },
        {
          chestPainName: '心包积液',
          chestPainCode: 'asc20'
        },
        {
          chestPainName: '主动脉管壁间血肿',
          chestPainCode: 'asc21'
        },
        {
          chestPainName: '透壁性动脉粥样硬化性溃疡',
          chestPainCode: 'asc22'
        },
        {
          chestPainName: '主动脉瘤',
          chestPainCode: 'asc23'
        },
        {
          chestPainName: '张力性气胸',
          chestPainCode: 'asc24'
        }
      ],
      // 心功能评级
      initialHeartDiagnosisList: [
        {
          initialHeartDiagnosisName: '心功能 I 级',
          initialHeartDiagnosisCode: 'killip1dia'
        },
        {
          initialHeartDiagnosisName: '心功能 II 级',
          initialHeartDiagnosisCode: 'killip2dia'
        },
        {
          initialHeartDiagnosisName: '心功能 III 级',
          initialHeartDiagnosisCode: 'killip3dia'
        },
        {
          initialHeartDiagnosisName: '心功能 IV 级',
          initialHeartDiagnosisCode: 'killip4dia'
        }
      ],
      // 其他非心源性胸痛
      cardiogenicList: [
        {
          cardiogenicName: '呼吸系统病',
          cardiogenicCode: 'other1'
        },
        {
          cardiogenicName: '消化系统病',
          cardiogenicCode: 'other2'
        },
        {
          cardiogenicName: '神经系统病',
          cardiogenicCode: 'other3'
        },
        {
          cardiogenicName: '精神系统病',
          cardiogenicCode: 'other4'
        },
        {
          cardiogenicName: '肌肉骨骼病',
          cardiogenicCode: 'other5'
        },
        {
          cardiogenicName: '皮肤系统病',
          cardiogenicCode: 'other6'
        },
        {
          cardiogenicName: '其他',
          cardiogenicCode: 'other7'
        }
      ],
      // 动脉夹层（A B型)
      initialDiagnosisTypeList: [
        {
          initialDiagnosisTypeName: 'A型',
          initialDiagnosisTypeCode: 'aorticdissection1'
        },
        {
          initialDiagnosisTypeName: 'B型',
          initialDiagnosisTypeCode: 'aorticdissection2'
        }
      ],
      // timi(stemi)评分-病史
      stemiMedicalHistoryList: [
        {
          stemiMedicalHistoryName: '年龄≥75岁',
          stemiMedicalHistoryCode: 'stemi1',
          stemiMedicalHistoryScore: 3
        },
        {
          stemiMedicalHistoryName: '年龄65~74岁',
          stemiMedicalHistoryCode: 'stemi2',
          stemiMedicalHistoryScore: 2
        },
        {
          stemiMedicalHistoryName: '糖尿病或高血压或心绞痛',
          stemiMedicalHistoryCode: 'stemi3',
          stemiMedicalHistoryScore: 1
        }
      ],
      // timi(stemi)评分-检查
      stemiInspectList: [
        {
          stemiInspectName: '收缩压<100mmHg',
          stemiInspectCode: 'stemi4',
          stemiInspectScore: 3
        },
        {
          stemiInspectName: '心率>100次/分',
          stemiInspectCode: 'stemi5',
          stemiInspectScore: 2
        },
        {
          stemiInspectName: 'Killp II~IV',
          stemiInspectCode: 'stemi6',
          stemiInspectScore: 2
        },
        {
          stemiInspectName: '体重<67kg',
          stemiInspectCode: 'stemi7',
          stemiInspectScore: 1
        },
        {
          stemiInspectName: '前壁ST段抬高或左束支传导阻滞',
          stemiInspectCode: 'stemi8',
          stemiInspectScore: 1
        },
        {
          stemiInspectName: '距离就诊时间>4h',
          stemiInspectCode: 'stemi9',
          stemiInspectScore: 1
        }
      ],
      // TIMI评分（NSTEMI/UA）
      nstemiProjectList: [
        {
          nstemiProjectName: '年龄（≥65岁）',
          nstemiProjectCode: 'nstemi1',
          nstemiProjectScore: 1
        },
        {
          nstemiProjectName:
            '≥3个冠心危险因子（家族史、高血压、高胆固醇、糖尿病、吸烟等）',
          nstemiProjectCode: 'nstemi2',
          nstemiProjectScore: 1
        },
        {
          nstemiProjectName: '已知冠心病（狭窄≥50%）',
          nstemiProjectCode: 'nstemi3',
          nstemiProjectScore: 1
        },
        {
          nstemiProjectName: '1周内使用阿司匹林',
          nstemiProjectCode: 'nstemi4',
          nstemiProjectScore: 1
        },
        {
          nstemiProjectName: '近期（≤24h）严重心绞痛（2次以上AP或静息AP）',
          nstemiProjectCode: 'nstemi5',
          nstemiProjectScore: 1
        },
        {
          nstemiProjectName: '心肌损伤指标升高',
          nstemiProjectCode: 'nstemi6',
          nstemiProjectScore: 1
        },
        {
          nstemiProjectName: 'ST段偏移≥0.05mm',
          nstemiProjectCode: 'nstemi7',
          nstemiProjectScore: 1
        }
      ],
      // GRACE 分级 Killip 分级
      graceKillipClassificationList: [
        {
          graceKillipClassificationName:
            'Ⅰ级 无心力衰竭征象，但PCWP(肺毛细血管楔嵌压)可升高，病死率0-5%',
          graceKillipClassificationCode: 'grace1'
        },
        {
          graceKillipClassificationName:
            'Ⅱ级 轻至中度心力衰竭，肺啰音出现范围小于两肺野的50%，可出现第三心音奔马律、持续性窦性心动过速或其它心律失常，静脉压升高，有肺淤血的X线表现，病死率10-20%',
          graceKillipClassificationCode: 'grace2'
        },
        {
          graceKillipClassificationName:
            'Ⅲ级 重度心力衰竭，出现急性肺水肿，肺啰音出现范围大于两肺的50%，病死率35-40%',
          graceKillipClassificationCode: 'grace3'
        },
        {
          graceKillipClassificationName:
            'Ⅳ级 出现心源性休克，收缩压小于90mmHg，尿少于每小时20ml，皮肤湿冷，发绀，呼吸加速，脉率大于100次/分，病死率 85-95%',
          graceKillipClassificationCode: 'grace4'
        }
      ],
      // GRACE分级 收缩压（mmHg）
      gracePressureClassificationList: [
        {
          gracePressureClassificationName: '<80',
          gracePressureClassificationCode: 'grace5'
        },
        {
          gracePressureClassificationName: '80-99',
          gracePressureClassificationCode: 'grace6'
        },
        {
          gracePressureClassificationName: '100-119',
          gracePressureClassificationCode: 'grace7'
        },
        {
          gracePressureClassificationName: '120-139',
          gracePressureClassificationCode: 'grace8'
        },
        {
          gracePressureClassificationName: '140-159',
          gracePressureClassificationCode: 'grace9'
        },
        {
          gracePressureClassificationName: '160-199',
          gracePressureClassificationCode: 'grace10'
        },
        {
          gracePressureClassificationName: '>200',
          gracePressureClassificationCode: 'grace11'
        }
      ],
      // GRACE分级 心率
      graceHeartRateClassificationList: [
        {
          graceHeartRateClassificationName: '<50',
          graceHeartRateClassificationCode: 'grace12'
        },
        {
          graceHeartRateClassificationName: '50-69',
          graceHeartRateClassificationCode: 'grace13'
        },
        {
          graceHeartRateClassificationName: '70-89',
          graceHeartRateClassificationCode: 'grace14'
        },
        {
          graceHeartRateClassificationName: '90-109',
          graceHeartRateClassificationCode: 'grace15'
        },
        {
          graceHeartRateClassificationName: '110-149',
          graceHeartRateClassificationCode: 'grace16'
        },
        {
          graceHeartRateClassificationName: '150-199',
          graceHeartRateClassificationCode: 'grace17'
        },
        {
          graceHeartRateClassificationName: '>200',
          graceHeartRateClassificationCode: 'grace18'
        }
      ],
      // GRACE分级 年龄（岁）
      graceAgeClassificationList: [
        {
          graceAgeClassificationName: '<30',
          graceAgeClassificationCode: 'grace19'
        },
        {
          graceAgeClassificationName: '30-39',
          graceAgeClassificationCode: 'grace20'
        },
        {
          graceAgeClassificationName: '40-49',
          graceAgeClassificationCode: 'grace21'
        },
        {
          graceAgeClassificationName: '50-59',
          graceAgeClassificationCode: 'grace22'
        },
        {
          graceAgeClassificationName: '60-69',
          graceAgeClassificationCode: 'grace23'
        },
        {
          graceAgeClassificationName: '70-79',
          graceAgeClassificationCode: 'grace24'
        },
        {
          graceAgeClassificationName: '>80',
          graceAgeClassificationCode: 'grace25'
        }
      ],
      // GRACE分级 CK(umol/L)
      graceCkClassificationList: [
        {
          graceCkClassificationName: '0-34',
          graceCkClassificationCode: 'grace26'
        },
        {
          graceCkClassificationName: '35-69',
          graceCkClassificationCode: 'grace27'
        },
        {
          graceCkClassificationName: '70-104',
          graceCkClassificationCode: 'grace28'
        },
        {
          graceCkClassificationName: '105-139',
          graceCkClassificationCode: 'grace29'
        },
        {
          graceCkClassificationName: '140-174',
          graceCkClassificationCode: 'grace30'
        },
        {
          graceCkClassificationName: '175-349',
          graceCkClassificationCode: 'grace31'
        },
        {
          graceCkClassificationName: '>350',
          graceCkClassificationCode: 'grace32'
        }
      ],
      // GRACE分级-危险因素
      graceDangerClassificationList: [
        {
          graceDangerClassificationName: '院前心跳骤停',
          graceDangerClassificationCode: 'grace33'
        },
        {
          graceDangerClassificationName: 'ST段下移',
          graceDangerClassificationCode: 'grace34'
        },
        {
          graceDangerClassificationName: '标记物升高',
          graceDangerClassificationCode: 'grace35'
        }
      ],
      // Killip 分级
      killipClassificationList: [
        {
          killipClassificationName:
            'I 无心力衰竭征象，但PCWP(肺毛细血管楔嵌压)可升高，病死率0-5%',
          killipClassificationCode: 'killip1'
        },
        {
          killipClassificationName:
            'II 轻至中度心力衰竭，肺啰音出现范围小于两肺野的50%，可出现第三心音奔马律、持续性窦性心动过速或其它心律失常，静脉压升高，有肺淤血的X线表现，病死率10-20%',
          killipClassificationCode: 'killip2'
        },
        {
          killipClassificationName:
            'III 重度心力衰竭，出现急性肺水肿，肺啰音出现范围大于两肺的50%，病死率35-40%',
          killipClassificationCode: 'killip3'
        },
        {
          killipClassificationName:
            'IV 出现心源性休克，收缩压小于90mmHg，尿少于每小时 20ml，皮肤湿冷，发绀，呼吸加速，脉率大于100次/分，病死率 85-95%',
          killipClassificationCode: 'killip4'
        }
      ],
      // NYHA 分级
      nyhaClassificationList: [
        {
          nyhaClassificationName:
            'Ⅰ级 患者有心脏病，但日常活动量不受限制，一般体力活动不引起过度疲劳、心悸、气喘或心绞痛',
          nyhaClassificationCode: 'nyha1'
        },
        {
          nyhaClassificationName:
            'Ⅱ级 心脏病患者的体力活动轻度受限制。休息时无自觉症状，一般体力活动引起过度疲劳、心悸、气喘或心绞痛。',
          nyhaClassificationCode: 'nyha2'
        },
        {
          nyhaClassificationName:
            'Ⅲ级 患者有心脏病，以致体力活动明显受限制。休息时无症状，但小于一般体力活动即可引起过度疲劳、心悸、气喘或心绞痛',
          nyhaClassificationCode: 'nyha'
        },
        {
          nyhaClassificationName:
            'Ⅳ级 心脏病患者不能从事任何体力活动，休息状态下也出现心衰症状，体力活动后加重',
          nyhaClassificationCode: 'nyha3'
        }
      ],
      outsData: { isGiveUp: '0' }
    }
  },
  watch: {},
  mounted() {
    this.getOutsData()
  },
  created() {
    this.findDiagnosesData()
    this.selectScoreClassAll()
  },
  methods: {
    getOutsData() {
      getOutsData(this.checkrowdata.dispatchId).then((res) => {
        if (res.data != null) {
          this.outsData = res.data
          this.outsData.isGiveUp = this.outsData.isGiveUp.toString()
        }
      })
    },
    saveOutsData(data) {
      saveOutsData(data).then((res) => {
        this.$message.success('保存成功')
        this.getOutsData()
      })
    },
    // 查询数据前初始化各Form表单
    initFormData() {
      this.diagnosisForm = []
      this.complicationForm = []
      this.stemiForm = []
      this.nstemiUAForm = []
      this.graceForm = []
      this.killipClassificationForm = []
      this.nyhaClassificationForm = []
    },
    historyTips(createdAt) {
      this.$message.info('请在 ' + createdAt + ' 的历史记录中修改时间')
    },
    findDiagnosesData() {
      findDiagnosesData({
        dispatchId: this.checkrowdata.dispatchId
      }).then((res) => {
        this.initFormData()
        if (res.length === 0) {
          this.hasData = false
        }
        res.forEach((item) => {
          if (item.diagnoseType === '初步诊断') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            // eslint-disable-next-line prefer-const
            let arr = this.JsonParse(item.diagnoseContent)
            // eslint-disable-next-line prefer-const
            let list = [
              ...this.initialDiagnosisList1,
              ...this.initialDiagnosisList2,
              ...this.initialDiagnosisList3
            ]
            item.diagnoseTime = item.diagnoseTime || item.createdAt
            obj.originData = item
            obj.initialDiagnosis = this.getComVal('initialDiagnosis', arr, list)
            obj.chestPain = this.getList('chestPain', arr)
            obj.initialHeartDiagnosis = this.getComVal(
              'initialHeartDiagnosis',
              arr
            )
            obj.cardiogenic = this.getList('cardiogenic', arr)
            obj.initialDiagnosisType = this.getComVal(
              'initialDiagnosisType',
              arr
            )
            this.diagnosisForm.push(obj)
          }
          if (item.diagnoseType === '并发症') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            obj.originData = item
            obj.complication = this.JsonParse(item.diagnoseContent)

            this.complicationForm.push(obj)
          }

          if (item.diagnoseType === 'TIMI评分（STEMI）') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            // eslint-disable-next-line prefer-const
            let arr = JSON.parse(item.diagnoseContent)
            obj.originData = item
            obj.score = item.score
            obj.grade = item.grade
            obj.stemiMedicalHistory = this.getList('stemiMedicalHistory', arr)
            obj.stemiInspect = this.getList('stemiInspect', arr)
            this.stemiForm.push(obj)
          }
          if (item.diagnoseType === 'TIMI评分（NSTEMI/UA）') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            // eslint-disable-next-line prefer-const
            let arr = this.JsonParse(item.diagnoseContent)
            obj.originData = item
            obj.score = item.score
            obj.grade = item.grade
            obj.nstemiProject = arr
            this.nstemiUAForm.push(obj)
          }
          if (item.diagnoseType === 'GRACE评分') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            // eslint-disable-next-line prefer-const
            let arr = this.JsonParse(item.diagnoseContent)
            obj.originData = item
            obj.graceKillipClassification = this.getComVal(
              'graceKillipClassification',
              arr
            )
            obj.gracePressureClassification = this.getComVal(
              'gracePressureClassification',
              arr
            )
            obj.graceHeartRateClassification = this.getComVal(
              'graceHeartRateClassification',
              arr
            )
            obj.graceAgeClassification = this.getComVal(
              'graceAgeClassification',
              arr
            )
            obj.graceCkClassification = this.getComVal(
              'graceCkClassification',
              arr
            )
            obj.graceDangerClassification = this.getComVal(
              'graceDangerClassification',
              arr
            )
            this.graceForm.push(obj)
          }
          if (item.diagnoseType === 'Killip分级') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            // eslint-disable-next-line prefer-const
            let arr = this.JsonParse(item.diagnoseContent)
            obj.originData = item
            obj.killipClassification = this.getComVal(
              'killipClassification',
              arr
            )
            this.killipClassificationForm.push(obj)
          }
          if (item.diagnoseType === 'NYHA分级') {
            // eslint-disable-next-line prefer-const
            let obj = {}
            // eslint-disable-next-line prefer-const
            let arr = this.JsonParse(item.diagnoseContent)
            obj.originData = item
            obj.nyhaClassification = this.getComVal('nyhaClassification', arr)
            this.nyhaClassificationForm.push(obj)
          }
        })
      })
    },
    // JSON字符串转换JSON格式
    JsonParse(val, index, type) {
      if (typeof val === 'undefined' || val == null || val === '') {
        return []
      } else {
        return JSON.parse(val.replace(/'/g, '"'))
      }
    },
    // 根据diagnoseContent数组字符串查找form对应的单选按钮字段
    getComVal(codeField, arr, list) {
      if (list) {
        return this.getValue(arr, list, codeField)
      } else {
        return this.getValue(arr, this[codeField + 'List'], codeField)
      }
    },

    getValue(arr, list, codeField) {
      let str = ''
      if (arr.length <= 0) {
        return str
      } else {
        arr.forEach((item) => {
          list.forEach((listItem) => {
            if (item === listItem[codeField + 'Code']) {
              str = item
            }
          })
        })
      }
      return str
    },
    // 根据diagnoseContent数组字符串查找form对应的复选框字段
    getList(codeField, arr) {
      const valList = []
      if (arr.length <= 0) {
        return valList
      } else {
        arr.forEach((item) => {
          this[codeField + 'List'].forEach((listItem) => {
            if (item === listItem[codeField + 'Code']) {
              valList.push(item)
            }
          })
        })
      }
      return valList
    },
    // TIMI（STEMI）评分计算
    stemiChange(index) {
      // 病史分数
      const num1 = this.getScoreSum(
        'stemiMedicalHistory',
        this.stemiForm[index]
      )
      // 检查分数
      const num2 = this.getScoreSum('stemiInspect', this.stemiForm[index])
      // 总分数
      this.stemiForm[index].score = num1 + num2
      // 等级评分
      this.stemiForm[index].grade = this.getStemiGrade(num1 + num2)
    },
    // TIMI评分（NSTEMI/UA）
    nstemiChange(index) {
      const num = this.getScoreSum('nstemiProject', this.nstemiUAForm[index])
      this.$set(this.nstemiUAForm[index], 'score', num)
      this.$set(this.nstemiUAForm[index], 'grade', this.getNstemiGrade(num))
    },
    // TIMI（NSTEMI/UA）等级计算
    getNstemiGrade(score) {
      if (score >= 0 && score <= 2) {
        return '低危'
      }
      if (score >= 3 && score <= 4) {
        return '中危'
      }
      if (score >= 5 && score <= 7) {
        return '高危'
      }
    },
    // TIMI（STEMI）等级计算
    getStemiGrade(score) {
      if (score >= 0 && score <= 3) {
        return '低危'
      }
      if (score >= 4 && score <= 6) {
        return '中危'
      }
      if (score >= 7 && score <= 14) {
        return '高危'
      }
    },

    // 计算评分分数方法
    getScoreSum(field, list) {
      let sum = 0
      list[field].forEach((el) => {
        sum += this.getScore(field, el)
      })
      return sum
    },
    getScore(field, val) {
      // eslint-disable-next-line prefer-const
      let obj = this[field + 'List'].find(
        (item) => item[field + 'Code'] === val
      )
      if (
        typeof obj[field + 'Score'] === 'undefined' ||
        obj[field + 'Score'] == null ||
        obj[field + 'Score'] === ''
      ) {
        return 0
      } else {
        return obj[field + 'Score']
      }
    },
    // 获取所有评分模板数据-接口
    selectScoreClassAll() {
      selectScoreClassAll({
        pageNum: 1,
        pageSize: 0,
        greenType: this.checkrowdata.diseaseType,
        hospitalId: this.$store.getters.hospitalId,
        type: ''
      }).then((res) => {
        if (res.code === 0) {
          const arr = res.data.list
          arr.forEach((item) => {
            item.floor = '0'
          })

          this.list = arr
          const selectList = arr.filter((item) => item.status !== '0')
          if (selectList.length > 0) {
            this.select = selectList[0].id
          }
          this.gradeInit()
          this.selectScores()
        } else {
          this.$message.error('查询评分模板失败')
        }
      })
    },
    // 查询评分数据-接口
    selectScores() {
      selectScores({
        dispatchId: this.checkrowdata.dispatchId,
        pageNum: 1,
        pageSize: 0
      }).then((res) => {
        if (res.code === 0) {
          this.scoresList = res.data.list
          this.scoreList = []
          res.data.list.forEach((item) => {
            this.list.forEach((el) => {
              if (parseInt(item.scoreClassAId) === el.id) {
                el.grade = this.compareRange(el.scoreConclusionList, item.score)
                // item.grade
                el.mark = item.score
                el.score = item
                this.scoreList.push(JSON.parse(JSON.stringify(el)))
              }
            })
          })
          this.scoreSetProcess()
          if (this.scoreList.length > 0) {
            this.hasData = true
          }

          this.timer = new Date().getTime()
        } else {
          this.$message.error('查询评分失败')
        }
      })
    },
    scoreSetProcess() {
      this.scoreList.forEach((item) => {
        item.data = item.score.index + '||' + item.score.score
        this.scoreSetSort(item.scoreClassList, item.score)
      })
    },
    scoreSetSort(list, score) {
      for (let i = 0; i < list.length; i++) {
        if (list[i].fieldType === 'content') {
          return false
        } else {
          if (!this.scoreSetSort(list[i].scoreClassList, score)) {
            list[i].data = score.index + '||' + score.score
          }
        }
      }
      return true
    },
    // 添加评分数据字段
    addConfirm() {
      const arr = this.list.filter((data) => data.id === this.select)
      const obj = this.scoreProcess(this.scoreSort(arr))
      obj.grade = this.compareRange(
        arr[0].scoreConclusionList ? arr[0].scoreConclusionList : [],
        this.addMark,
        true
      )
      // this.addGrade

      obj.mark = this.addMark
      obj.userId = this.checkrowdata.userId
      obj.dispatchId = this.checkrowdata.dispatchId
      obj.medicalId = this.checkrowdata.medicalId
      obj.scoreClassAId = this.select
      console.log(obj.index, 'obj')
      if (!obj.index) {
        this.$message.error('没有选中的选项无法添加')
      } else {
        this.saveScores(obj)
      }
    },
    // 添加评分-接口
    saveScores(obj) {
      saveScores([obj]).then((res) => {
        if (res.code === 0) {
          this.openAddDialog = false
          this.$message.success('新增成功')
          this.selectScoreClassAll()
        } else {
          this.$message.error('新增失败')
        }
      })
    },
    // 获取分值等级-接口
    getGrade() {
      const obj = this.scoreProcess(
        this.scoreSort(this.list.filter((data) => data.id === this.select))
      )
      if (obj.score) {
        selectScoreConclusion({
          hospitalId: this.$store.getters.hospitalId,
          scoreId: this.select
        }).then((res) => {
          this.addGrade = this.compareRange(res.data.list, obj.score)
        })
      }
    },
    // 收取评分数据
    scoreSort(list) {
      let arr = []
      for (let i = 0; i < list.length; i++) {
        if (list[i].data) {
          arr.push(list[i].data)
        } else {
          arr = arr.concat(this.scoreSort(list[i].scoreClassBList))
        }
      }
      return arr
    },
    // 评分数据处理
    scoreProcess(arr) {
      const indexArr = []
      let score = ''
      arr.forEach((el) => {
        if (el.indexOf('||') > 0) {
          indexArr.push(el.split('||')[0])
          if (!score) {
            score = parseInt(el.split('||')[1])
          } else {
            score += parseInt(el.split('||')[1])
          }
        } else {
          indexArr.push(el)
        }
      })
      return {
        index: indexArr.join(','),
        score: score
      }
    },
    // 获取比较分值的结论
    compareRange(list, score, flag) {
      if (list.length === 0) {
        if (!flag) {
          return '未录入描述信息，请联系医院管理员'
        } else {
          return ''
        }
      }
      if (!score && score !== 0) {
        return ''
      } else {
        for (let i = 0; i < list.length; i++) {
          const max = score + ''
          if (list[i].maxcondition && list[i].maximum) {
            max = score + list[i].maxcondition + list[i].maximum
          }
          const min = score + ''
          if (list[i].mincondition && list[i].minimum) {
            min = score + list[i].mincondition + list[i].minimum
          }
          if (
            (this.calculator(min) || this.calculator(min) === 0) &&
            (this.calculator(max) || this.calculator(max) === 0)
          ) {
            return list[i].conclusion
          }
        }
      }
      if (!flag) {
        return '所得分值无对应结论，请联系医院管理员'
      } else {
        return ''
      }
    },
    // 字符串比较计算器
    calculator(str) {
      return new Function('return (' + str + ')')()
    },
    // 打开新增弹框
    openAdd() {
      if (this.list.length > 0) {
        this.openAddDialog = true
      } else {
        this.$message.error('未录入评分模板')
      }
    },
    requireCheck(from) {
      console.log(from)
      console.log("this.addDiagnosisForm", this.addDiagnosisForm)
      let tips = false
      // 其它非心源性胸痛
      if (this.addDiagnosisForm.initialDiagnosis == 'othercardiogenic' || from.initialDiagnosis == 'othercardiogenic') {
        console.log(from.originData.diagnoseContent == '', !from.originData.diagnoseContent0)
        console.log("val", from.originData.diagnoseContent == '' || !from.originData.diagnoseContent)
        if (from.cardiogenic.length === 0) {
          tips = '其它非心源性胸痛'
        }
      } else if (this.addDiagnosisForm.initialDiagnosis == 'aorticdissection' || from.initialDiagnosis == 'aorticdissection') {
        if (from.initialDiagnosisType == '' || !from.initialDiagnosisType) {
          tips = '主动脉夹层'
        }
        // 主动脉夹层
      } else if (this.addDiagnosisForm.initialDiagnosis == "Non-ACS_cardiogenic_chest_pain" || from.initialDiagnosis == 'Non-ACS_cardiogenic_chest_pain') {
        // 非ACS心源性胸痛
        // tips = '非ACS心源性胸痛类型'
        console.log(from.chestPain, from.chestPain.length === 0)
        if (from.chestPain.length === 0) {
          tips = '非ACS心源性胸痛类型'
        }
        // if (!from.initialDiagnosis || from.chestPain == '' || !from.chestPain || from.chestPain.length == 0) {
        //   // console.log(from)
        //   console.log(from.initialHeartDiagnosis == '', !from.initialDiagnosis, from.chestPain == '', !from.chestPain, from.chestPain.length == 0)
        //   tips = '非ACS心源性胸痛类型'
        // }
      }


      if (tips) {
        this.$message.warning(tips + '不能为空')
        return
      }
      return true
    },
    // 修改评分数据
    save(item) {
      const obj = this.scoreProcess(this.scoreSort([item]))
      obj.id = item.score.id
      obj.userId = this.checkrowdata.userId
      obj.dispatchId = this.checkrowdata.dispatchId
      obj.medicalId = this.checkrowdata.medicalId
      obj.scoreClassAId = item.id
      obj.grade = this.compareRange(item.scoreConclusionList, obj.score, true)
      // item.grade
      if (item.status !== '0') {
        this.updateScores(obj)
      } else {
        this.$message.error('此评分已禁用，不允许修改')
      }
    },
    updateScores(obj) {
      updateScores([obj]).then((res) => {
        if (res.code === 0) {
          this.$message.success('保存成功')

          this.selectScoreClassAll()
        } else {
          this.$message.error('保存失败')
        }
      })
    },
    gradeInit() {
      this.addGrade = ''
    },
    getAddGrade(item) {
      const obj = this.scoreProcess(this.scoreSort([item]))
      console.log(obj)
      this.addMark = obj.score
      if (item.scoreConclusionList) {
        this.addGrade = this.compareRange(item.scoreConclusionList, obj.score)
      }
    },
    getGradeSpan(item, index) {
      const obj = this.scoreProcess(this.scoreSort([item]))
      this.scoreList[index].mark = obj.score
      if (item.scoreConclusionList) {
        this.scoreList[index].grade = this.compareRange(
          item.scoreConclusionList,
          obj.score
        )
      }
    },
    saveOther(form) {
      console.log('form', form)
      if (!this.requireCheck(form)) {
        return
      }
      saveOutsData(this.outsData)
      // eslint-disable-next-line prefer-const
      let originData = form.originData
      // eslint-disable-next-line prefer-const
      let diagnoseContent = []
      if (form.score) {
        originData.score = form.score
      }
      if (form.grade) {
        originData.grade = form.grade
      }
      delete form.grade
      for (const key in form) {
        if (key !== 'originData' && typeof form[key] === 'string') {
          if (
            !(
              typeof form[key] === 'undefined' ||
              form[key] == null ||
              form[key] === ''
            )
          ) {
            diagnoseContent.push(form[key])
          }
        } else if (key !== 'originData' && typeof form[key] === 'object') {
          diagnoseContent.push(...form[key])
        }
      }
      originData.diagnoseContent = JSON.stringify(diagnoseContent)
      if (originData.diagnoseType == '初步诊断' && !form.initialDiagnosis) {
        this.$message.warning('请选择初步诊断')
      } else if (
        originData.diagnoseType == '初步诊断' &&
        (form.initialDiagnosis == 'siemidia' ||
          form.initialDiagnosis == 'nstemidia') &&
        !form.initialHeartDiagnosis
      ) {
        this.$message.warning('请选择心功能等级')
      } else {
        this.saveDiagnoses(originData)
      }
    },
    // 调用保存数据接口
    saveDiagnoses(data) {
      saveDiagnoses(data).then((res) => {
        if (res.code === 0) {
          this.openAddDiagnosis = false
          this.openAddComplication = false
          this.$message.success('保存成功')
          this.findDiagnosesData()
        } else {
          this.$message.error('保存失败')
        }
      })
    },
    addDiagnosis() {
      this.openAddDiagnosis = true
      this.addDiagnosisForm = {
        originData: {},
        chestPain: [],
        cardiogenic: []
      }
    },
    addComplication() {
      this.openAddComplication = true
      this.addComplicationForm = {
        originData: {},
        complication: []
      }
    },
    addDiagnosisConfirm(field, type) {
      this[field].originData.department = this.checkrowdata.departmentName
      this[field].originData.diagnoseType = type
      this[field].originData.user = this.$store.getters.name
      this[field].originData.userId = this.$store.getters.userId
      this[field].originData.medicalId = this.checkrowdata.medicalId
      this[field].originData.dispatchId = this.checkrowdata.dispatchId
      this.saveOther(this[field])
    }
  }
}
</script>

<style lang="scss" scoped>
.body {
  padding-left: 20px;
  padding-right: 20px;
  padding-top: 20px;

  .no-data {
    padding: 20px 40px;
    margin-bottom: 20px;
  }

  .form {
    margin: 0px 25px 20px 15px;
    padding-bottom: 0px;
    border: 1px solid #dcdfe6;

    &-title {
      display: flex;
      align-items: center;
      line-height: 36px;
    }

    &-row {
      padding-right: 20px;
      padding: 12px 30px;
      border-bottom: 1px solid #dcdfe6;
    }
  }

  .card {
    margin: -1px 45px 0px 35px;
    padding: 10px 20px 0px 10px;
    border-top: 1px dashed #dcdfe6;
    border-radius: 4px;

    &-title,
    &-subTitle {
      margin-bottom: 10px;
      font-size: 15px;

      .right {
        display: flex;
        justify-content: flex-end;

        div {
          padding-left: 20px;
        }
      }

      .content {
        display: flex;
        align-items: center;
      }
    }

    &-subTitle {
      padding: 7px 0;
    }

    &-content {
      padding-left: 30px;
      font-size: 14px !important;

      .el-radio {
        min-width: 80px;
      }

      .radio-flex {
        .small-distance {
          margin-right: 0px;
          min-width: 60px !important;
        }

        .el-radio {
          min-width: 110px;
          margin: 0px 20px 20px 0px;
        }

        .small .el-checkbox {
          min-width: 110px;
        }

        .el-checkbox {
          margin: 0px 10px 20px 0px !important;
          min-width: 226.3px;
        }
      }

      .check {
        width: 750px;
      }

      &-result {
        margin: 0px 0px 20px;
      }

      .radio-box .el-radio {
        min-width: 200px;
        padding: 3px 0;
      }

      &-title {
        display: flex;
        flex: 0 0 45px;
        align-items: center;
      }

      &-subTitle {
        display: flex;
        flex: 0 0 45px;
      }

      .item {
        .row {
          padding-bottom: 20px;

          span {
            font-size: 14px;
            font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
          }
        }
      }

      .inspect {
        width: 750px;
      }

      .project {
        width: 1000px;
        margin-top: 5px;
        margin-bottom: 15px;
      }

      .result-grade {
        .el-input {
          width: 280px;
        }
      }

      .result-score {
        padding-left: 20px;
        padding-right: 10px;

        .el-input {
          width: 50px;
        }
      }
    }
  }
}
</style>

<style lang="scss">
.estimateAddDialog {
  .el-dialog__body {
    padding: 0 25px;
  }
}

.required-field:before {
  content: "*";
  color: red;
  margin-right: 2px;
}

.line-hr {
  border: 0.25px solid rgb(220, 223, 230);
}

.left-h2 {
  margin-left: 20px;
}
</style>
